class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        unordered_map<char,int> hash1;
        unordered_map<char,int> hash2;
        vector<int> ret;
        for(auto e:p)
        {
            hash1[e]++;
            hash2[e]=0;
        }
        for(int left=0,right=0;right<s.size();right++)
        {
            if(hash1.find(s[right])==hash1.end())
            {
                left=right+1;
                for(auto& e:hash2)
                    e.second=0;
            }
            else
            {
                hash2[s[right]]++;
                while(hash2[s[right]]>hash1[s[right]])
                {
                    hash2[s[left]]--;
                    left++;
                }
                if(right-left+1==p.size())
                {
                    ret.push_back(left);
                }
            }
        }
        return ret;
    }
};